<?php
/*
 * class.province.php
 * 商家省份
 * @version 0.1
 * @author samuel
 * @date 2009-05-10
 */
include_once 'class.sellerBase.php';
class seller_province extends sellerBase {
    private $step;
    private $classname;
    private $tpl_file;

    function  __construct($core) {
        parent::__construct();
        
        //参数处理
        $this->step = $this->params['step'];
        if(!$this->step) $this->step = "list";
        $this->classname = strtolower(trim(get_class($this)));
        $this->tpl_file = $this->classname . "_" . $this->step . ".html";
        
        $this->run();
    }

    function run(){
        var_dump($this->step);
        switch($this->step){
            case 'list':
                $page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_provinces_info = $this->getSellerProvinceList("", array("SellerProvinceID"=>"desc"), $arr_limit);
                $arr_provinces = $arr_provinces_info['list'];
                $pager = $arr_provinces_info['pager'];
                $this->core->tpl->assign('arr_provinces', $arr_provinces);
                $this->core->tpl->assign('pager', $pager);
                break;
            case 'add':
                break;
            case 'do_add':
                $province_name = $this->params['SellerProvinceNameCN'];
                $province_char = $this->params['SellerProvinceChar'];
                $tag = $this->addNewProvince($province_name, $province_char);
                if(!$tag){
                    $this->core->utility->messagePrompt($this->error);
                }

                $this->core->utility->messagePrompt('添加成功!');
                return;
                break;
            case 'edit':
                $pid = $this->params['pid'];
                $province = $this->getSellerProvinceInfo($pid);
				$this->core->tpl->assign('province', $province);
                break;
			case 'do_edit':
				$pid = $this->params['pid'];
				$province_info['name'] = $this->params['SellerProvinceNameCN'];
				$province_info['char'] = $this->params['SellerProvinceChar'];
				$this->updateProvince($pid, $province_info);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('更新成功！');
				}
				return;
				break;
			case 'del':
				$pid = $this->params['pid'];
				$this->delProvince($pid);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
				return;
				break;
            case 'batch_del':
                $pids = $this->params['checkboxes'];
                if(is_array($pids)){
                    foreach($pids as $pid){
                        $this->delProvince($pid);
                    }
                }
                if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
                return;
                break;
			case 'search':
				$search_pname = $this->params['search_pname'];
				$search_pchar = $this->params['search_pchar'];
				$search_url_append = "&step=".$this->step."&search_pname=".$search_pname."&search_pchar=".$search_pchar;
				$arr_filter = array();
				if($search_pname){
					$arr_filter[] = array('attr'=>'SellerProvinceNameCN', 'value'=>$search_pname, 'match'=>'like');
				}
				if($search_pchar){
					$arr_filter[] = array('attr'=>'SellerProvinceChar', 'value'=>$search_pchar, 'match'=>'like');
				}
				$page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . $search_url_append;
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_provinces_info = $this->getSellerProvinceList($arr_filter, array("SellerProvinceID"=>"desc"), $arr_limit);
                $arr_provinces = $arr_provinces_info['list'];
                $pager = $arr_provinces_info['pager'];
                $this->core->tpl->assign('arr_provinces', $arr_provinces);
                $this->core->tpl->assign('pager', $pager);
				//共用一个模板
				$this->tpl_file = "seller_province_list.html";
				break;
        }
        $this->core->tpl->display($this->tpl_file);
    }
}
?>